# -*- coding: utf-8 -*-
import MySQLdb as mdb
import re

client = mdb.connect(
    host='0.0.0.0',
    port=3306,
    user='root',
    passwd='ilove1388',
    db='cbook',
    charset='utf8'
)
client.autocommit(True)

cursor = client.cursor()
query_count_sql = 'SELECT (book_custom_item_id) FROM book_tag_reflection WHERE book_custom_item_id like "doukan_"'
cursor.execute(query_count_sql, None)

for item in cursor.fetchall():

  # item_id从url中获取
  item_id_pattern = re.compile(r'\d+')
  found = item_id_pattern.findall(item[0])
  item_id = None
  if found:
      item_id = found[0]

  if item_id is not None:

    print item_id

    update_book_price_sql = 'UPDATE book_tag_reflection SET book_custom_item_id=%s WHERE book_custom_item_id=%s'
    cursor.execute(update_book_price_sql, [
        'duokan_'+item_id,
        item[0]
    ])

print 'over'
cursor.close()